-- 战报弹窗
local GuildWarFightReportPop = class("GuildWarFightReportPop", app.mvc.ViewBase)

local ListViewVertical = require("app.widget.listview.ListViewVertical")
local GuildWarFightReportTitleCell = import("..renders.GuildWarFightReportTitleCell")
local GuildWarFightReportInfoCell = import("..renders.GuildWarFightReportInfoCell")
local NewguildIconRender = require("app.newGuild.views.renders.NewguildIconRender")

GuildWarFightReportPop.VIEW_ROOT_RES = Res.CSGuildWarFightReport

function GuildWarFightReportPop:init()
    self.super.init(self)
    display.setCascadeOpacityEnabled(self._root, true)
    self._ui.Button_close:addClickEventListener(function()
        self:closeView()
    end)
    self:registerViewEvent({
        {name = ViewEvent.CSGuildWar_FightReport, callback = handler(self, self._onGetReportData)},
       
    })

    local params = {
        cellConfigs = {
            [1] = {renderClass = GuildWarFightReportTitleCell, perNum = 1},
            [2] = {renderClass = GuildWarFightReportInfoCell, perNum = 1},
        },
        cellTagMarkFunc = function(data)
            return data.tag
        end,
        cellEventProxy = function(eventName, params)
			
		end,
    }   
    self._listview = ListViewVertical.new(self._ui["Panel/ScrollView"], params)

    self._guildIconRender1 = NewguildIconRender.create(self._ui["Panel/Panel_top/icon_1"])
    self._guildIconRender2 = NewguildIconRender.create(self._ui["Panel/Panel_top/icon_2"])
   
end


-- function GuildWarFightReportPop:requestFightReport(matchId)
--     if matchId then
--         UD.csGuildWarData:C2S_WorldGuildWarReport(matchId)
--     end
-- end

function GuildWarFightReportPop:_onGetReportData(eventName, reportInfo)
    if not reportInfo then
        return
    end
    self._reportInfo = reportInfo
    local listviewData =  {}

    local curRound = -1
    for k, v in pairs( reportInfo:getReports()) do
        if v:getRound() ~= curRound then
            curRound = v:getRound()
            table.insert(listviewData, {tag = 1, round = curRound})
        end
        table.insert(listviewData, {tag = 2, data = v})
    end
    self:refreshTop()
    self._listview:reloadData(listviewData)
    self._ui["Panel/Panel_tips"]:setVisible(#listviewData == 0)
end


function GuildWarFightReportPop:refresh()
    
end

function GuildWarFightReportPop:refreshTop()
    if not self._reportInfo then
        return
    end
    local guild1 = self._reportInfo:getGuild1()
    local leftNum1 = 0
    local wDay = app:getWeekDayPassDailyUpdate()
    if guild1 then
        self._ui["Panel/Panel_top/Panel_data_1"]:setVisible(true)
        self._guildIconRender1:setVisible(true)
        self._guildIconRender1:setData(guild1:getGuildIconData())
        self._ui["Panel/Panel_top/Panel_data_1/server"]:setString(guild1:getServerName())
        self._ui["Panel/Panel_top/Panel_data_1/guild"]:setString(guild1:getGuildName())
        if wDay >= 6 then
            self._ui["Panel/Panel_top/Panel_data_1/ranking"]:setString(string.format(L("WGWPreGameRank"), guild1:getRank()))
        else
            self._ui["Panel/Panel_top/Panel_data_1/ranking"]:setString(string.format(L("WGWCurrentRank"), guild1:getRank()))
        end
        leftNum1 = guild1:getMemberLifeNum()
    else
        self._ui["Panel/Panel_top/Panel_data_1"]:setVisible(false)
        self._guildIconRender1:setVisible(false)
    end

    local guild2 = self._reportInfo:getGuild2()
    local leftNum2 = 0
    if guild2 then
        self._ui["Panel/Panel_top/Panel_data_2"]:setVisible(true)
        self._guildIconRender2:setVisible(true)
        self._guildIconRender2:setData(guild2:getGuildIconData())
        self._ui["Panel/Panel_top/Panel_data_2/server"]:setString(guild2:getServerName())
        self._ui["Panel/Panel_top/Panel_data_2/guild"]:setString(guild2:getGuildName())
        leftNum2 = guild2:getMemberLifeNum()
        if wDay >= 6 then
            self._ui["Panel/Panel_top/Panel_data_2/ranking"]:setString(string.format(L("WGWPreGameRank"), guild2:getRank()))
        else
            self._ui["Panel/Panel_top/Panel_data_2/ranking"]:setString(string.format(L("WGWCurrentRank"), guild2:getRank()))
        end
    else
        self._ui["Panel/Panel_top/Panel_data_2"]:setVisible(false)
        self._guildIconRender2:setVisible(false)
    end
    self._ui["Panel/Panel_top/num_1"]:setString(leftNum1)
    self._ui["Panel/Panel_top/num_2"]:setString(leftNum2)
end

    

return GuildWarFightReportPop